package com.open.capacity.notice.controller;

import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.open.capacity.common.dto.ResponseEntity;
import com.open.capacity.common.utils.EntityUtils;
import com.open.capacity.common.validator.UpdateGroup;
import com.open.capacity.notice.dmo.MessageRececiverGroup;
import com.open.capacity.notice.dto.MessageRececiverGroupDto;
import com.open.capacity.notice.service.MessageRececiverGroupService;
import com.open.capacity.notice.vo.MessageRececiverGroupVO;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 前端控制器
 * </p>
 * 
 * @since 2024-05-07
 */
@RestController
@SuppressWarnings("all")
@RequiredArgsConstructor
@RequestMapping("/messageRececiverGroup")
public class MessageRececiverGroupController {

	private final MessageRececiverGroupService messageRececiverGroupService;

	/**
	 * 分页列表查询
	 *
	 * @param messageRececiverGroupDto
	 * @param page
	 * @return
	 */
	@ApiOperation(value = "接收组管理-分页列表查询", notes = "接收组管理-分页列表查询")
	@GetMapping(value = "/list")
	public ResponseEntity queryPageList(MessageRececiverGroupDto messageRececiverGroupDto, Page page) {
		MessageRececiverGroup messageRececiverGroup = EntityUtils.toObj(messageRececiverGroupDto,
				MessageRececiverGroup::new);
		IPage<MessageRececiverGroup> pageList = messageRececiverGroupService.page(page,
				Wrappers.query(messageRececiverGroup));
		return ResponseEntity.succeed(pageList);
	}

	/**
	 * 添加
	 *
	 * @param MessageRececiverGroupDto
	 * @return
	 */
	@PostMapping(value = "/add")
	@ApiOperation(value = "接收组管理-添加", notes = "接收组管理-添加")
	public ResponseEntity<MessageRececiverGroup> add(@Valid @RequestBody MessageRececiverGroupDto messageRececiverGroupDto) {
		return ResponseEntity.succeed(messageRececiverGroupService.add(messageRececiverGroupDto), "添加成功");
	}

	/**
	 * 编辑
	 *
	 * @param messageRececiverGroupDto
	 * @return
	 */
	@ApiOperation(value = "接收组管理-编辑", notes = "接收组管理-编辑")
	@PostMapping(value = "/edit")
	public ResponseEntity<MessageRececiverGroup> edit(@Validated({ UpdateGroup.class })  @RequestBody MessageRececiverGroupDto messageRececiverGroupDto) {
		return ResponseEntity.succeed(messageRececiverGroupService.edit(messageRececiverGroupDto), "编辑成功");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "接收组管理-通过id查询", notes = "接收组管理-通过id查询")
	@GetMapping(value = "/query-by-id")
	public ResponseEntity<MessageRececiverGroupVO> queryById(@RequestParam(name = "id") String id) {
		return ResponseEntity.succeed(messageRececiverGroupService.queryById(id));
	}

	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "接收组管理-通过id删除", notes = "接收组管理-通过id删除")
	@PostMapping(value = "/delete")
	public ResponseEntity<Boolean> delete(@RequestParam(name = "id") String id) {
		return ResponseEntity.succeed(messageRececiverGroupService.delete(id), "删除成功");
	}

}
